import Vue from 'vue'
import App from './App.vue'
//import {Button,Row} from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import ElementUI from 'element-ui';
import router from './router';
import store from './store';
import './api/mock'
import Cookies from 'js-cookie';

Vue.config.productionTip = false
// Vue.use(Row);
// Vue.use(Button)
Vue.use(ElementUI)

//添加前置
router.beforeEach((to, from, next) => {
  //判断token存不存在
  const token = Cookies.get('token')
  // token不存在，说明用户为登录应该跳转至登录页
  if (!token && to.name !== 'login') {
    next({ name: 'login' })
  } else if (token && to.name === 'login') {//token存在
    next({ name:'home' })
  } else {
    next()
  }
})

new Vue({
  router,
  store,
  render: h => h(App),
  created(){
    store.commit('addMenu',router)
  }
}).$mount('#app')
